﻿<UserControl x:Class="DemoApp.ToolBoxControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:s="clr-namespace:DiagramDesigner;assembly=DiagramDesigner"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    
    <Border BorderBrush="LightGray"
            BorderThickness="1">
        <StackPanel>
            <Expander Header="Symbols"
                      IsExpanded="True">
                <ItemsControl ItemsSource="{Binding ToolBoxItems}">
                    <ItemsControl.Template>
                        <ControlTemplate TargetType="{x:Type ItemsControl}">
                            <Border BorderThickness="{TemplateBinding Border.BorderThickness}"
                                    Padding="{TemplateBinding Control.Padding}"
                                    BorderBrush="{TemplateBinding Border.BorderBrush}"
                                    Background="{TemplateBinding Panel.Background}"
                                    SnapsToDevicePixels="True">
                                <ScrollViewer VerticalScrollBarVisibility="Auto">
                                    <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                                </ScrollViewer>
                            </Border>
                        </ControlTemplate>
                    </ItemsControl.Template>
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel Margin="0,5,0,5"
                                       ItemHeight="50"
                                       ItemWidth="50" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemContainerStyle>
                        <Style TargetType="{x:Type ContentPresenter}">
                            <Setter Property="Control.Padding"
                                    Value="10" />
                            <Setter Property="ContentControl.HorizontalContentAlignment"
                                    Value="Stretch" />
                            <Setter Property="ContentControl.VerticalContentAlignment"
                                    Value="Stretch" />
                            <Setter Property="ToolTip"
                                    Value="{Binding ToolTip}" />
                            <Setter Property="s:DragAndDropProps.EnabledForDrag"
                                    Value="True" />
                        </Style>
                    </ItemsControl.ItemContainerStyle>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Image IsHitTestVisible="True"
                                   Stretch="Fill"
                                   Width="50"
                                   Height="50"
                                   Source="{Binding ImageUrl, Converter={x:Static s:ImageUrlConverter.Instance}}" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Expander>
        </StackPanel>
    </Border>
</UserControl>
